package com.starhub.application.collection.enums;

import lombok.Getter;

/**
 * 知识库表业务类型枚举
 * @version: V1.0
 * @author: liuhf
 * @time 2025-06-06
 */
@Getter
public enum CollectionTypeEnums {
    
    MAIN_DATA(0, "主数据表"),
    QA_DATA(1, "知识问答表"),
    META_DATA(2, "元数据表");

    private final Integer code;
    private final String desc;

    CollectionTypeEnums(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据code获取枚举值
     * @param code
     * @return
     */
    public static CollectionTypeEnums getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (CollectionTypeEnums type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据code获取描述
     * @param code
     * @return
     */
    public static String getDescByCode(Integer code) {
        CollectionTypeEnums type = getByCode(code);
        return type == null ? null : type.getDesc();
    }

    /**
     * 判断code是否有效
     * @param code
     * @return
     */
    public static boolean isValid(Integer code) {
        return getByCode(code) != null;
    }
}
